package com.allen.Service;

import com.allen.Back;
import com.allen.pojo.Account;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

public class BackServerHandler implements Runnable {
    private Socket socket;


    public BackServerHandler(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            String response = "";
            inputStream = socket.getInputStream();
            outputStream = socket.getOutputStream();
            int count = 0;
            String content = null;
            byte[] bytes = new byte[1024];
            while ((count = inputStream.read(bytes)) != -1) {
                response=new String(bytes, 0, count, "utf-8");
                System.out.println(response);
                if(response.equals("0")){
                    content="请保管好信用卡，欢迎下次光临";
                    outputStream.write(content.getBytes());
                    outputStream.flush();
                    break;
                }
                if(response.equals("1")){
                    //存款
                }
                if(response.equals("2")){
                    //取款
                }
                content="请继续操作";
                outputStream.write(content.getBytes());
                outputStream.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
